#include "bits/stdc++.h"

using namespace std;

struct cup {
  char country[200];
  int win, same, lose, win_ball, lose_ball;
  int score;
  int pure_win;
};

bool com(cup A, cup B){
  if (A.score == B.score) {
    return A.pure_win > B.pure_win;
  }
  else {
    return A.score > B.score;
  }
}

int main(int argc, char const *argv[]) {
  int N, M;
  cin>>N>>M;
  struct cup CUP[N];
  for (int i = 0; i < N; i++) {
    cin>>CUP[i].country>>CUP[i].win>>CUP[i].same>>CUP[i].lose>>CUP[i].win_ball>>CUP[i].lose_ball;
    CUP[i].score = 3*CUP[i].win + CUP[i].same;
    CUP[i].pure_win = CUP[i].win_ball - CUP[i].lose_ball;
  }
  sort(CUP, CUP+N, com);
  for (int i = 0; i < M; i++) {
    cout<<i + 1<<" "<<CUP[i].country<<" "<<CUP[i].score<<" "<<CUP[i].pure_win<<endl;
  }
  return 0;
}
